import 'package:flutter/material.dart';

import './rank/tab_item_widget.dart';
import './rank/leftmenurightlist.dart';
import '../../../model/ranktabitem.dart';

class RankList extends StatefulWidget {
  RankList({Key? key}) : super(key: key);

  @override
  State<RankList> createState() => _RankListState();
}

class _RankListState extends State<RankList> {
  List<TabItem> tabItemList = [
    TabItem('1', title: '周榜', isChecked: false),
    TabItem('2', title: '月榜', isChecked: false),
    TabItem('3', title: '总榜', isChecked: false),
  ];

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned(
          top: 0,
          child: Container(
            width: MediaQuery.of(context).size.width,
            padding: EdgeInsets.all(8.0),
            decoration: BoxDecoration(
                border:
                    Border(bottom: BorderSide(color: Colors.grey.shade400))),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: tabItemList
                    .map((item) => GestureDetector(
                          onTap: () {
                            setState(() {
                              tabItemList = tabItemList
                                  .map((e) => (e == item
                                      ? TabItem(
                                          e.classId,
                                          title: e.title,
                                          isChecked: !e.isChecked!,
                                        )
                                      : TabItem(
                                          e.classId,
                                          title: e.title,
                                          isChecked: false,
                                        )))
                                  .toList();
                            });
                          },
                          child: TabItemWidget(item),
                        ))
                    .toList()),
          ),
        ),
        LeftMenuRightList(),
      ],
    );
  }
}
